package com.yzs.core.http

import com.yzs.core.momory.AppManager
import okhttp3.Interceptor
import okhttp3.Response

/**
 * author : yzs
 * time   : 2021/06/28
 * desc   : 请求拦截器 统一添加请求头参数
 */
class HeaderInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder = chain.request().newBuilder()
        val token = AppManager.token
        if (token.isNotEmpty()) builder.addHeader("Authorization", "Bearer $token")
        val request = builder.build()
        return chain.proceed(request)
    }
}